/**
 * pointwidget 模块.
 */

var FG;
if (!FG)
    FG = {};

FG.LW_TEMPLATE = _.template(
    //'<div class="pointwidget" id="pw-<%= uuid %>">' +
    '<div><%= uuid %></div>'
);

FG.MultiLineWidget = FG.FeatureWidgetBase.extend({
    includes: [L.Mixin.Events ],

    options: {
        minWidth: 50,
        maxWidth: 1000,
        // maxHeight: null,
        autoPan: true,
        closeButton: false,
        offset: [0, 7],
        autoPanPadding: [45, 60],
        //autoPanPadding: [100, 100],
        autoPanPaddingTopLeft: [355, 60],
        autoPanPaddingBottomRight: [45, 45],
        keepInView: false,
        zoomAnimation: true,
        className: '',
        widgetClassName: 'linewidget',
        widgetTemplate: FG.LW_TEMPLATE,
        widgetPrefix: 'leaflet-linewidget',
        widgetType: 'line'
    },

    renderModel: function(model) {
        this._renderModelBasic(model);
        this.setContent(this.$content[0]);
        this.genSnapshot({
            uuid: this.model.get('uuid'),
            update: true
        });
        return this;
    },

    switchViewport: function(viewport) {
        var this_ = this;
        DX.warn(viewport);
    },

    genSnapshot: function(opts) {
        var this_ = this,
            model = this.model;
        var opts = _.extend({}, opts);

        var status = {
            pitem: model.get('uuid'),
            parameters: {}
        };

        if (_.has(this_._source, 'imageUrl') && this_._source.imageUrl !== ''){
            thumbnail = '/data/' + this_._source.imageUrl;
        } else {
            thumbnail = ''
        }

        var svgStr = '';

        var nowStr = moment().format('YY/MM/DD hh:mm');
        if (!!opts.update && !!opts.uuid) {
            DX.shout('snapshot:update!',
                {
                    uuid: opts.uuid,
                    pitem_uuid: model.get('uuid'),
                    pitem: model,
                    html: svgStr,
                    thumbnail: thumbnail,
                    type: '',
                    desc: '',
                    caption: nowStr,
                    status: status
                })
        } else {
            DX.shout('snapshot:take!',
                {
                    uuid: DX.gen_uuid16(),
                    pitem_uuid: model.get('uuid'),
                    pitem: model,
                    html: svgStr,
                    thumbnail: thumbnail,
                    type: '',
                    desc: '',
                    caption: nowStr,
                    status: status
                });
        }
    }
});
// 生成widget
FG.getMultiLineWidget = function(opts, widgetOpts, source) {
    var this_ = this;
    this.widgetOpts = _.extend({}, widgetOpts);

    var widget = new FG.MultiLineWidget(this.widgetOpts, source);
    return widget;
};


